package src.main.java.org.thread;

public class ThreadTest1 {
    //main方法是一条默认的主线程负责执行
    public static void main(String[] args) {
        System.out.println("====继承Thread======");
        Thread thread = new MyThread("1");
        //启动线程
        thread.start();
        for (int i = 0; i < 5; i++) {
            System.out.println("主线程main输出："+i);
        }
        System.out.println("======实现Runnable接口=========");
        //创建任务对象
        /*Runnable myRunnable = new MyRunnable();
        new Thread(myRunnable).start();*/
        //匿名内部类写法
        //1.创建Runnable接口的匿名内部类形式
/*        Runnable target = new Runnable(){
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println("子线程输出："+i);
                }
            }
        };
        new Thread(target).start();*/
        //简化形式
/*        new Thread(new Runnable(){
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println("子线程输出："+i);
                }
            }
        }).start();*/
        //继续简化
        new Thread(()-> {
                for (int i = 0; i < 5; i++) {
                    System.out.println("子线程输出："+i);
                }
        }).start();

    }
}
